package com.changgou;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author ljh
 * @version 1.0
 * @date 2021/1/2 08:46
 * @description 标题
 * @package com.changgou
 */

@SpringBootApplication
@EnableEurekaClient
public class GatewayAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayAdminApplication.class,args);
    }
    //设置keyresolver (限流的标准参照的key)
    @Bean(name="ipKeyResolver")
    public KeyResolver userKeyResolver(){
        return new KeyResolver() {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                //以ip地址的方式
                String hostAddress = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();//ip地址
                return Mono.just(hostAddress);
            }
        };
    }
}
